home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 276-300 / 299 / rxil / src / diag.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  5KB  |  260 lines

  1. /* diag.c */
  2.  
  3. /*        Copyright © 1989 by Donald T. Meyer, Stormgate Software
  4.  *        All Rights Reserved
  5.  */
  6.  
  7.  
  8.  
  9. #include "rxil.h"
  10.  
  11. #include <string.h>
  12. #include <stdio.h>
  13.  
  14.  
  15.  
  16. static void dump_env( struct RxilDef *rdef );
  17. static void dump_state( struct RxilDef *rdef );
  18. static void dump_cmds( struct RxilDef *rdef );
  19. static void dump_rxi( struct RxilInvocation *rxi );
  20.  
  21. static void leftword( char *buffer, char *source );
  22. static int strpos( char *s, unsigned int c );
  23.  
  24.  
  25.  
  26. /* NAME
  27.  *        RxilDumpRdef
  28.  *
  29.  * SYNOPSIS
  30.  *        RxilDumpRdef( rdef, flags );
  31.  *
  32.  *        struct RxilDef *rdef;
  33.  *        ULONG flags;
  34.  *
  35.  * FUNCTION
  36.  *        This function is for debug and testing purposes.  It will
  37.  *        dump information about the current ARexx environment to the
  38.  *        CLI.
  39.  *
  40.  * INPUTS
  41.  *        rdef = pointer to the global RxilDef structure.
  42.  *        flags = an unsigned long whose bits control just what information
  43.  *            about the RxilDef structure is displayed.
  44.  *
  45.  * RESULT
  46.  *        None
  47.  *
  48.  * SIDES
  49.  *
  50.  * HISTORY
  51.  *        01-Aug-89    Creation.
  52.  *        25-Sep-89    Added display of library version string.
  53.  *        01-Oct-89    Added "flags" argument to control just what is
  54.  *                    displayed, and ability to display the commands.
  55.  *        10-Nov-89    Changed format of command info display slightly.
  56.  *
  57.  * BUGS
  58.  *
  59.  * SEE ALSO
  60.  *
  61.  */
  62.  
  63. void RxilDumpRdef( struct RxilDef *rdef, ULONG flags )
  64. {
  65.     printf( "\n%s\n\n", rdef->Version );
  66.  
  67.     if(  FlagIsSet( flags, RXIL_DUMP_CMDS )  )
  68.     {
  69.         dump_cmds( rdef );
  70.         printf( "\n" );
  71.     }
  72.  
  73.     if(  FlagIsSet( flags, RXIL_DUMP_ENV )  )
  74.     {
  75.         dump_env( rdef );
  76.         printf( "\n" );
  77.     }
  78.  
  79.     if(  FlagIsSet( flags, RXIL_DUMP_STATE )  )
  80.     {
  81.         dump_state( rdef );
  82.         printf( "\n" );
  83.     }
  84. }
  85.  
  86.  
  87.  
  88. static void dump_env( struct RxilDef *rdef )
  89. {
  90.     printf( "Public Port name: %s\n", rdef->PortName );
  91.     printf( "Secret Port name: %s\n", rdef->SecretPortName );
  92.  
  93.     if( rdef->Console )
  94.     {
  95.         printf( "Console: %s\n", rdef->Console );
  96.     }
  97.     else
  98.     {
  99.         printf( "No console will be used\n" );
  100.     }
  101.  
  102.     printf( "Macro extension: %s\n", rdef->Extension );
  103.     printf( "Invocation messages sent to port: %s\n", rdef->HostPort );
  104. }
  105.  
  106.  
  107.  
  108. static void dump_cmds( struct RxilDef *rdef )
  109. {
  110.     unsigned int i;
  111.     char *cf, *pl;
  112.  
  113.  
  114.     printf( "  Command Name      Arguments    Case     Privilege\n\n" );
  115.  
  116.     for( i=0; rdef->CommandTable[i].Name != NULL; i++ )
  117.     {
  118.         if( rdef->CommandTable[i].CaseFlag == TRUE )
  119.         {
  120.             cf = "Matters";
  121.         }
  122.         else
  123.         {
  124.             cf = "Ignored";
  125.         }
  126.  
  127.         pl = (rdef->CommandTable[i].Privilege > RXIL_PUBLIC) ?
  128.             "*Private*" : "Public   ";
  129.  
  130.  
  131.         if( rdef->CommandTable[i].MinArgs ==
  132.             rdef->CommandTable[i].MaxArgs )
  133.         {
  134.             /* Argument count is fixed */
  135.  
  136.             printf( "%-18s     %2d      %s    %s\n",
  137.                 rdef->CommandTable[i].Name,
  138.                 (int)rdef->CommandTable[i].MinArgs,
  139.                 cf, pl );
  140.         }
  141.         else
  142.         {
  143.             /* Argument count is variable */
  144.  
  145.             printf( "%-18s   %2d -%2d    %s    %s\n",
  146.                 rdef->CommandTable[i].Name,
  147.                 (int)rdef->CommandTable[i].MinArgs,
  148.                 (int)rdef->CommandTable[i].MaxArgs,
  149.                 cf, pl );
  150.         }
  151.     }
  152. }
  153.  
  154.  
  155.  
  156. static void dump_state( struct RxilDef *rdef )
  157. {
  158.     struct RxilInvocation *rxi;
  159.  
  160.  
  161.     printf( "Lock count: %d\n", rdef->LockCount );
  162.  
  163.     if( rdef->Invocations )
  164.     {
  165.         rxi = rdef->Invocations;
  166.         while( rxi )
  167.         {
  168.             dump_rxi( rxi );
  169.             rxi = rxi->Next;
  170.         }
  171.     }
  172.     else
  173.     {
  174.         printf( "No invocation structures allocated\n" );
  175.     }
  176. }
  177.  
  178.  
  179.  
  180. static void dump_rxi( struct RxilInvocation *rxi )
  181. {
  182.     char *s;
  183.     char buf[128] = "(no name)";
  184.  
  185.  
  186.     if( rxi->Name )
  187.     {
  188.         leftword( buf, rxi->Name );
  189.     }
  190.  
  191.     printf( "\nInvocation: %s\n", buf );
  192.  
  193.  
  194.     switch( rxi->State )
  195.     {
  196.         case RXIL_STATE_AVAILABLE:
  197.             s = "Available";
  198.             break;
  199.  
  200.         case RXIL_STATE_PENDING:
  201.             s = "Pending";
  202.             break;
  203.  
  204.         case RXIL_STATE_RETURNED:
  205.             s = "Returned";
  206.             break;
  207.     }
  208.  
  209.     printf( "\tState: %s\n", s );
  210.  
  211.     if( rxi->Parent )
  212.     {
  213.         printf( "This is a child of a Macro\n" );
  214.     }
  215.  
  216.     if( rxi->Console )
  217.     {
  218.         printf( "The console is: %s\n", rxi->Console );
  219.     }
  220. }
  221.  
  222.  
  223.  
  224. /* This will take the leftmost word (delimited by a space) from the
  225.  * string pointed to by source and move it to the buffer pointed
  226.  * to by buffer.  If there is no space in the source string, the
  227.  * entire thing will be copied.
  228. */
  229.  
  230. static void leftword( char *buffer, char *source )
  231. {
  232.     unsigned int p;
  233.  
  234.     if( p = strpos( source, ' ' ) )
  235.     {
  236.         /* There is a space, so all we want is the leftmost word */
  237.         strncpy( buffer, source, p-1 );
  238.         buffer[p-1] = '\0';
  239.     }
  240.     else   strcpy( buffer, source );
  241. }
  242.  
  243.  
  244.  
  245. /* This routine returns the leftmost position in which it finds
  246.  * the desired character.  A null is returned if the character
  247.  * is not found in the string.  The first character in the string
  248.  * is considered to be position 1.
  249. */
  250.  
  251. static int strpos( char *s, unsigned int c )
  252. {
  253.     char *x;
  254.  
  255.     x = strchr( s, c );
  256.     if( x==0 )   return( 0 );
  257.     else   return( (int)(x-s+1) );
  258. }
  259.  
  260.